package com.aaa.service;

import com.aaa.dao.ExamDao;
import com.aaa.dao.impl.ExamDaoImpl;
import com.aaa.entity.ExamEntity;
import com.aaa.entity.Message;
import com.aaa.entity.Pager;
import com.aaa.entity.ScoreEntity;
import com.aaa.util.PageUtil;

import java.util.List;
import java.util.Map;

/**
 * fileName:ExamServiceImpl
 * description:
 * author:王宇航
 * createTime:2019/10/10 14:11
 * version:1.0.0
 */
public class ExamServiceImpl implements ExamService{
    ExamDao dao=new ExamDaoImpl();

    @Override
    public Pager queryAll(int pageNo) {
        int pageSize= PageUtil.PAGE_SIZE;
        return dao.queryAll(pageNo,pageSize);
    }

    @Override
    public Message Update(ExamEntity examEntity) {
        Message message=new Message();
        int result=-1;
        if(examEntity.getId()==0){
            result=dao.exam_add(examEntity);
            if (result>=1){
                message=new Message(200,"录入成功");
            }else {
                message=new Message(300,"录入失败");
            }
        }else {
            result=dao.exam_update(examEntity);
            if (result>=1){
                message=new Message(200,"修改成功");
            }else {
                message=new Message(300,"修改失败");
            }
        }
        return message;
    }

    @Override
    public Map queryOne(int id) {
        return dao.queryOne(id);
    }

    @Override
    public int delete(int id) {
        return dao.exam_delete(id);
    }

    @Override
    public int updateState(int id, int state) {
        return dao.updateState(id,state);
    }

    @Override
    public List queryClass() {
        return dao.queryClass();
    }

    @Override
    public List queryStu(int classid) {
        return dao.queryStu(classid);
    }

    @Override
    public int addScore(List<ScoreEntity> list) {
        for (int i = 0; i < list.size(); i++) {
           dao.addScore(list.get(i));
        }
        return 0;
    }
}
